#!/usr/bin/python

import os, socket, sys

child = 0

def usage():
    print "Usage: " + sys.argv[0] + " <program to patrol> <IP address of fuzzer>"
    exit(0)

def unixCitizenPatrol(program,sock):
    start = "valgrind " + program

    # Start, find and attach to XChat

    os.system(start)

    sock.send("0")
    try: 
        buffer = sock.recv(100000)
        print "\nCrash with fuzz case number " + buffer
    except:
        print "\nGOD DAMMIT"
    sock.close()
    
    exit(0)

def main():
    if (len(sys.argv) != 3):
        usage()

    # Connect to shit-storm
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((sys.argv[2], 2444))

    # Unix debugger
    unixCitizenPatrol(sys.argv[1],sock)

main()

